{include file='public/head'}
<style type="text/css" media="screen">
    header {
        color: black;
    }
    .x-body {
        min-width: 400px;
    }

    body {
        overflow-x: scroll;
    }
</style>
<body>
<div class="x-body">
    <form class="layui-form" id='mainForm' method="post" action="lookGoodAdd">
        <input type="hidden" name="order_id" id="order_id" value="{$Think.get.order_id}">
        <input type="hidden" name="asin" id="asin" value="{$Think.get.asin}">
        <input type="hidden" name="shop_id" id="shop_id" value="{$Think.get.shop_id}">
        <div class="layui-form-item">
            <label class="layui-form-label">角&nbsp;&nbsp;&nbsp;色</label>
            <div class="layui-input-block">
                <select name="role_id" id='role_id' lay-verify="required" lay-filter="role_id">
                    <option value="">请选择</option>
                    {volist name="roles" id="vo"}
                    <option value="{$vo.id}">{$vo.title}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">采购员</label>
            <div class="layui-input-block">
                <select name="user_id" id='user_id' lay-verify="required" lay-filter="user_id">

                </select>
            </div>
            <input type="hidden" id="linkman" name="linkman" value="">
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">补充备注</label>
            <div class="layui-input-block">
                <textarea id="remark" name="remark" placeholder="请输入" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div>
                <button style="width: 100%" class="layui-btn" lay-submit="" lay-filter="toSubmit">提交保存</button>
            </div>
        </div>

    </form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
    var form = layui.form;

    form.on('select(role_id)', function (data) {
        $("#user_id").html("");
        $.ajax({
            url: "getUser",
            async: true,
            dataType: 'json',
            data: {role_id: data.value},
            type: "post",
            success: function (res) {
                var html = '<option value="">请选择</option>';
                for (var i = 0; i < res.length; i++) {
                    html += "<option value=" + res[i].id + ">" + res[i].truename + "</option>";
                }
                $("#user_id").append(html);
                form.render('select');
            }
        })
    });

    form.on('select(user_id)', function (data) {
        $("#linkman").val(data.elem[data.elem.selectedIndex].text);
    });

    $(document).ready(function () {
        var form = layui.form;
        var layer = layui.layer;
        var options = {
            type: 'post',           //post提交
            // url:'http://ask.tongzhuo100.com/server/****.php?='+Math.random(),   //url
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };

        // bind form using 'ajaxForm'
        $('#mainForm').ajaxForm(options).submit(function (data) {
        });
    });
</script>
</html>
